/*
 * @Description:
 * @Author: maxyang
 * @Date: 2022-06-05 17:59:38
 * @LastEditTime: 2022-06-28 20:33:44
 * @LastEditors: liutq
 * @Reference:
 */
package admin

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/maxyang107/jinglan/common"
	"github.com/maxyang107/jinglan/model/announcement"
	"github.com/maxyang107/jinglan/service/admin"
)

/**
 * @description: 方法描述：发布公告
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func AddAnnouncement(c *gin.Context) {
	var annP announcement.Announcement

	if err := c.ShouldBind(&annP); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}

	err := admin.AdminAnnouncementService.AddAnnouncement(annP)

	if err != nil {
		common.ResponseToJson(http.StatusOK, common.Fail, err.Error(), c)
		return
	}

	common.ResponseToJson(http.StatusOK, common.Ok, "公告发布成功", c)
}

/**
 * @description: 方法描述：修改公告
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func ModifyAnnouncement(c *gin.Context) {
	var annP announcement.Announcement

	if err := c.ShouldBind(&annP); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}

	err := admin.AdminAnnouncementService.ModifyAnnouncement(annP)

	if err != nil {
		common.ResponseToJson(http.StatusOK, common.Fail, err.Error(), c)
		return
	}

	common.ResponseToJson(http.StatusOK, common.Ok, "公告修改成功", c)
}
